package com.zzyl.service.impl;

import com.zzyl.dto.BedDto;
import com.zzyl.entity.Bed;
import com.zzyl.mapper.BedMapper;
import com.zzyl.service.BedService;
import com.zzyl.vo.BedVo;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class BedServiceImpl implements BedService {

    @Autowired
    private BedMapper bedMapper;

    @Override
    public List<BedVo> getBedsByRoomId(Long roomId) {
        return bedMapper.getBedsByRoomId(roomId);
    }

    /**
     * 新增床位
     *
     * @param bedVo 前端传递的床位数据
     */
    @Override
    public void addBed(BedVo bedVo) {
        Bed bed = new Bed();
        BeanUtils.copyProperties(bedVo,bed);
        bedMapper.addBed(bed);
    }

    /**
     * 根据ID查询床位信息
     *
     * @param id 床位ID
     * @return
     */
    @Override
    public BedVo getBedById(Long id) {
        Bed bed = bedMapper.getBedById(id);
        BedVo vo = new BedVo();
        BeanUtils.copyProperties(bed,vo);
        return vo;
    }

    /**
     * 修改床位信息
     *
     * @param bedDto
     */
    @Override
    public void updateBed(BedDto bedDto) {
        Bed bed = new Bed();
        BeanUtils.copyProperties(bedDto,bed);
        bedMapper.updateBed(bed);
    }

    /**
     * 根据id删除床位
     *
     * @param id
     */
    @Override
    public void deleteBed(Long id) {
        bedMapper.deleteBedById(id);
    }

}

